package com.aurora.source.home.presenter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;

import com.aurora.source.base.BaseBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.constant.AuroraConstants;
import com.aurora.source.home.bean.ContactUsDataBean;
import com.aurora.source.home.view.IContactUsView;
import com.aurora.source.util.netutil.SubscriberObserver;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ContactUsPresenter extends BasePresenter<IContactUsView> {

    public ContactUsPresenter(IContactUsView baseView) {
        super(baseView);
    }

    public void ContactUsSource(Context context,Map<String, String> params) {
        requestMethod.contactUs(params, new SubscriberObserver<BaseBean<ContactUsDataBean>>(context,"正在加载中...") {
            @Override
            public void onSuccess(BaseBean<ContactUsDataBean> contactUsDataBeanBaseBean) {
                Log.e("sss",contactUsDataBeanBaseBean.getMsg());
                if (contactUsDataBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)) {
                    baseView.onContactUsSuccess(contactUsDataBeanBaseBean.getData());
                } else {
                    baseView.onContactUsFail(contactUsDataBeanBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                Log.e("sss",msg);
                baseView.onContactUsFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    public void upDataQualiImg(Context context,Map<String, String> editParams, File file) {
        requestMethod.updateCompanyHonorOrQuarantine(editParams, file, new SubscriberObserver<BaseBean>(context,"正在修改图片...") {
            @Override
            public void onSuccess(BaseBean baseBean) {
                if(baseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onUpDataSuccess(baseBean.getMsg());
                }else {
                    baseView.onUpDataFail(baseBean.getMsg());
                }

            }

            @Override
            public void onError(String msg) {
                baseView.onUpDataFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    /**
     * 删除企业资源
     * @param updateType 0企业Banner 1企业视频 3荣誉资质 4检疫报告
     * @param companyId
     * @param deleteResourceId
     */
    public void deleteCompanyResource(Context context,int updateType, String companyId, String deleteResourceId) {
        Map<String,String> params = new HashMap<>();
        params.put("updateType",updateType+"");
        params.put("companyId",companyId);
        params.put("deleteResourceId",deleteResourceId);
        requestMethod.deleteCompanyResource(params,new SubscriberObserver<BaseBean>(context,"正在删除图片...") {
            @Override
            public void onSuccess(BaseBean baseBean) {
                if(baseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onUpDataSuccess(baseBean.getMsg());
                }else {
                    baseView.onUpDataFail(baseBean.getMsg());
                }

            }

            @Override
            public void onError(String msg) {
                baseView.onUpDataFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    //修改公司图片或者视频
    public void upDataCopImgOrVideo(Context context, Map<String, String> editParams2, File file, Bitmap localVideoThumbnail) {
        requestMethod.upDataCopImgOrVideo(editParams2, file,localVideoThumbnail, new SubscriberObserver<BaseBean>(context,"正在上传资源...") {
            @Override
            public void onSuccess(BaseBean baseBean) {
                if(baseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onUpDataSuccess(baseBean.getMsg());
                }else {
                    baseView.onUpDataFail(baseBean.getMsg());
                }

            }

            @Override
            public void onError(String msg) {
                baseView.onUpDataFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    /**
     * 修改企业信息
     * @param context
     * @param params
     */
    public void upDataCopInfo(Context context, Map<String, String> params) {
        requestMethod.upDataCopInfo(params, new SubscriberObserver<BaseBean>(context,"正在提交数据...") {
            @Override
            public void onSuccess(BaseBean contactUsDataBeanBaseBean) {
                Log.e("sss",contactUsDataBeanBaseBean.getMsg());
                if (contactUsDataBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)) {
                    baseView.onUpDataSuccess(contactUsDataBeanBaseBean.getMsg());
                } else {
                    baseView.onUpDataFail(contactUsDataBeanBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                Log.e("sss",msg);
                baseView.onUpDataFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }
}